package com.pw.gmall.realtime.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author: linux_future
 * @since: 2022/3/21
 **/
public class RedisUtils {

    private static JedisPool pool;

    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);
        config.setMaxIdle(10);
        config.setMaxWaitMillis(30 * 1000);
        config.setMinIdle(2);
        config.setTestOnCreate(true);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);

        pool = new JedisPool(config, "hadoop162", 6379);
    }

    public static Jedis getClient() {
        System.out.println("================redis===============");
        Jedis jedis = pool.getResource();
        jedis.select(1);

        return jedis;
    }

}
